<!DOCTYPE html>
<!--suppress ThymeleafVariablesResolveInspection-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>调整班级</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
    <link th:href="@{/assets/plugins/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/assets/plugins/font-awesome/css/font-awesome.min.css}" rel="stylesheet">
    <link th:href="@{/assets/css/custom.css}" rel="stylesheet">
    <script th:src="@{/assets/plugins/jquery/jquery-3.1.0.min.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>
</head>
<body>
<form class="layui-form" action="">

    <div th:each="s:${stu}">
        <input type="hidden" name="clazzend" th:value="${s.clazz}">
        <input type="hidden" name="studid" th:value="${s.studid}">
        <input type="hidden" name="stuname" th:value="${s.stuname}">
    <div class="layui-form-item" style="margin-top: 25px">
        <label class="layui-form-label">班级</label>
        <div class="layui-input-inline">
            <select lay-filter="selectTheme" id="board" name="jiebie">-->
                <option value="0" >请选择届别</option>
                <option  th:each="sf:${studentfallList}" th:value="${sf.fallid}" th:text="${sf.level}">所在系</option>
            </select>

        </div>

        <div class="layui-input-inline">
            <select id="theme" name="clazz">
                <option></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="ok()" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
        </div>
    </div>
    </div>
</form>
<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;
        form.on('select(selectTheme)', function (data) {//对应lay-filter="selectTheme"
            var index1 = $('#board option:selected').val();//对应id="board"  得到一级菜单选中值的value
            var optionJson = [];
            $.ajax({
                url: "/stu/byfallid",//对应controller层
                type: "post",
                data: {"classno": index1},//将选中值的value传给controller
                datatype: "json",
                success: function (data) {
                    optionJson = data;
                    var selectObj = document.getElementById("theme");//对应id="theme"
                    selectObj.options.length = 0;
                    for (var i = 0; i < data.length; i++) {
                        selectObj.add(new Option(optionJson[i].classname, optionJson[i].classid));//对应数据库中名字，两个参数是(文本,value)
                    }
                    form.render();
                }
            })
        });


        //监听提交
        //你可以在这里做操作  也可以不使用这个方法
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url: '/stu/clazzupd',
                type: 'post',
                data:data.field,
                dataType: 'json',
                success:function(data){
                    if(data){
                        layer.msg(JSON.stringify("添加成功"));
                        //先得到当前iframe层的索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //再执行关闭
                        parent.layer.close(index);
                        window.parent.location.reload();
                    }
                },
            })
            //$('.layui-laypage-btn').click();//刷新
            return false;
        });
    });
</script>
</body>
</html>